package com.qf.strategy.service.Impl;

import com.qf.strategy.service.QueueService;
import com.qianfeng.smsplatform.common.constants.RabbitMqConsants;
import com.qianfeng.smsplatform.common.model.Standard_Report;
import com.qianfeng.smsplatform.common.model.Standard_Submit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @author 徐老板
 * @date 2020/3/3   16:31
 */
@Service
public class QueueServiceImpl implements QueueService {
    private static final  Logger LOGGER = LoggerFactory.getLogger(QueueServiceImpl.class);
    @Resource
    private RabbitTemplate rabbitTemplate;
    @Override
    public void sendSearchMQ(Standard_Submit submit, String errorCode) {
        LOGGER.error("发送给搜索模块的消息是{},错误码是{}",submit,errorCode);
        //这里需要把没有值的数据补全
        submit.setErrorCode(errorCode);//错误码
        submit.setReportState(2);//状态
        submit.setSendTime(new Date());//发送时间
        rabbitTemplate.convertAndSend(RabbitMqConsants.TOPIC_SMS_SEND_LOG,submit );
    }

    @Override
    public void pushInterface(Standard_Submit submit, String errCode) {
        //这里需要判断用户来源 如果是从接口模块出来的返回给接口
        //这个来源在接口模块传过来的数据中
        //从后台过来的 不需要吧
        if (submit.getSource()==1){
            Standard_Report report=new Standard_Report();
            report.setClientID(submit.getClientID());
            report.setErrorCode(errCode);
            report.setMobile(submit.getDestMobile());
            //这个代表同一用户发送好多短信 这个是具体哪条短信的
            report.setSrcID(submit.getSrcSequenceId());
            report.setState(2);
            //这个rabbitmq是靠map传递的
            rabbitTemplate.convertAndSend(RabbitMqConsants.TOPIC_PUSH_SMS_REPORT,report );
        }
    }
}
